/**
 * @file form action
 * @author liaoxuezhi@baidu.com
 */
/* eslint fecs-indent: [0, "space", 2, 2] */

import {
  UPDATE_FORM,
  CLEAR_FORM,
  REQ_FETCH_FORM,
  REC_FETCH_FORM,
  REQ_FETCH_CHECK_FORM,
  REC_FETCH_CHECK_FORM,
  REQ_FETCH_FORM_SCHEMA,
  REC_FETCH_FORM_SCHEMA,
  REQ_SAVE_FORM,
  REC_SAVE_FORM,
  REQ_FORM_ACTION,
  REC_FORM_ACTION,
  REQ_CHECK_FORM,
  REC_CHECK_FORM
} from './action-types';
import {createScopedAction, createAjaxAction} from '../renderer';

// export function updateForm(name, data, modified = true) {
//   const action = createScopedAction(name, UPDATE_FORM);
//
//   return dispatch => dispatch(action({
//     data,
//     modified
//   }));
// }

export const fetchForm = createAjaxAction('get', REQ_FETCH_FORM, REC_FETCH_FORM);
export const fetchCheckForm = createAjaxAction('get', REQ_FETCH_CHECK_FORM, REC_FETCH_CHECK_FORM);
export const fetchSchema = createAjaxAction('get', REQ_FETCH_FORM_SCHEMA, REC_FETCH_FORM_SCHEMA);
export const saveForm = createAjaxAction('post', REQ_SAVE_FORM, REC_SAVE_FORM);
export const doAction = createAjaxAction('post', REQ_FORM_ACTION, REC_FORM_ACTION);
export const checkForm = createAjaxAction('get', REQ_CHECK_FORM, REC_CHECK_FORM);


export function clearForm(name, data = null) {
  const action = createScopedAction(name, CLEAR_FORM);

  return dispatch => dispatch(action({
    data
  }));
}